<!DOCTYPE html>
<html>
<head>
    <title>$app.topic 抢单券管理</title>
    #parse("/inc/meta.htm")
</head>
<body id="inner_page_start">

<div class="modal fade" id="loading" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop='static'>
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">提示</h4>
            </div>
            <div class="modal-body">
                请稍候。。。<span id="result"></span>
            </div>
        </div>
    </div>
</div>

#parse("/inc/header.htm")

<div id="wrapper">

    #parse("/inc/menu.htm")

    <div id="content-wrapper">

        <div class="container-fluid">

            <!-- 面包屑-->
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    抢单券管理
                </li>
                <li class="breadcrumb-item active">抢单券列表</li>
            </ol>

            <div class="card mb-3">
                <div class="card-body">
                    <form id="list_form" action="/bills/list" >
                        <input type="hidden" name="page"  id="list_page" value="$respData.pagenumber" />
                        <div class="form-inline">
                            <div class="form-group mx-sm-3">
                                <label>使用状态:
                                    <select name="state" class="form-control">
                                        <option value="" >全部</option>
                                        <option value="0" #if($form.state == 0) selected #end>未使用</option>
                                        <option value="1" #if($form.state == 1) selected #end>已使用</option>
                                    </select>
                                </label>
                            </div>
                            <div class="form-group mx-sm-3">
                                <label>发放状态:
                                    <select name="check" class="form-control">
                                        <option value="" >全部</option>
                                        <option value="0" #if($form.check == 0) selected #end>未领取</option>
                                        <option value="1" #if($form.check == 1 ) selected #end>已领取</option>
                                    </select>
                                </label>
                            </div>
                            <div class="form-group mx-sm-3">
                                <button type="button" onclick="doCreate()"
                                        class="btn btn-danger">生成抢单码</button>
                            </div>

                            <div class="form-group mx-sm-3">
                                <div class="dataTables_filter float-right">
                                    <button class="btn btn-primary"  onclick="jump('list_form',1)">搜索</button>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-sm-12 col-md-12"  >
                                <div class="form-inline float-right">
                                    <label>显示
                                        <select name="rows"  onchange="submit()"  class="form-control">
                                            <option value="10" #if($respData.pagerow == 10) selected #end>10</option>
                                            <option value="15" #if($respData.pagerow == 15) selected #end>15</option>
                                            <option value="20" #if($respData.pagerow == 20) selected #end>20</option>
                                            <option value="25" #if($respData.pagerow == 25) selected #end>25</option>
                                        </select>
                                        行</label>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 table-outer-box">
                                <table class="table table-bordered dataTable" id="dataTable" width="100%" cellspacing="0" role="grid" aria-describedby="dataTable_info" style="width: 100%;">
                                    <thead>
                                    <tr role="row">
                                        <th>用户</th>
                                        <th>状态</th>
                                        <th>使用状态</th>
                                        <th>类型</th>
                                        <th>抢单码</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <!--$!{tagInfo["1"]["$row.source"].name}-->
                                    #foreach( $row in ${respData.getRows()} )
                                    <tr>
                                        <td>$!row.uname</td>
                                        <td>
                                            #if($!row.uid == 0)
                                                未领取
                                            #else
                                                已领取
                                            #end
                                        </td>
                                        <td>
                                            #if($!row.state == 0)
                                                未使用
                                            #elseif($!row.state == 1)
                                                已使用
                                            #else
                                                未知
                                            #end
                                        </td>
                                        <td>
                                            #if($!row.type == 0)
                                                抢单券
                                            #elseif($!row.type == 1)
                                                优惠券
                                            #else
                                                未知
                                            #end
                                        </td>
                                        <td>$!row.code</td>
                                        <td>
                                        </td>
                                    </tr>
                                    #end
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 col-md-5">
                                <div class="dataTables_info" id="dataTable_info" role="status" aria-live="polite">
                                    显示 $!respData.s 到 $!respData.e 一共 $!respData.total 条
                                </div>
                            </div>
                            <div class="col-sm-12 col-md-7">
                                <div class="dataTables_paginate paging_simple_numbers" id="dataTable_paginate">
                                    <ul class="pagination float-right">
                                        #page("/bills/list?rows=$!respData.1" $respData )
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
        <!-- /.container-fluid -->
        #parse("/inc/copyright.htm")
    </div>
    <!-- /.content-wrapper -->
</div>

#parse("/inc/footer.htm")
<script>
    function doCreate() {
        $('#loading').modal('show');
        $.ajax({
            url: "/bills/create",
            type: "get",
            success: function(data) {
                if (data.state == "000") {
                    $("#result").text("生成数据成功")
                    setTimeout(function () {
                        window.location.href = "/bills/list"
                    },400)
                } else {
                    closeTab("生成数据失败：服务异常")
                }
            },
            error: function(obj,ex,msg) {
                closeTab("生成数据失败：网络错误")
            }
        });
    }

    function closeTab(msg) {
        $("#result").text(msg)
        setTimeout("$('#loading').modal('hide')",1000)
    }
</script>
</body>
</html>